####################################################-*- coding: utf-8 -*-#####
#
#
# This is the toplevel driver which initializes all parser threads and runs
# command thread.
#
#
##############################################################################
import sys
if sys.version_info[0] < 3:
    print('\n[ERROR] This tool can be only ran with python 3.x\n')
    exit()
    
from threading import Thread, Lock, Event
from command import Command
from log import Log
from basic_info_parser import StockInfoParser


if __name__ == '__main__':
    # TODO: Read threading config from stock.cfg

    lock = Lock() 

    log = Log.getInstance()
    cmd = Command.getInstance()
    #db  = Database()    
    #infoparser = StockInfoParser()

    cmd.start()
    log.start()
    #db.start()       # db thread should start before any parser thread
    #inforparser.start()

    #cmd.foo(lock)
    #cmd.bar(lock)

    cmd.wait()          # exit all other threads if command exits
    # NOTE: quit sequece: the object who is used by other object should
    #       be exited after its user exits.
    #infoparser.exit()
    log.exit()
